export function makePrefix(prefix: string, split = '/'): (n: string) => string {
  return (n: string): string => {
    const lastIndex = prefix.lastIndexOf(split)
    if (lastIndex === prefix.length - 1) {
      prefix = prefix.substring(0, lastIndex)
    }

    return `${prefix}${split}${n}`
  }
}

export function formatStr(srcString: string, params: unknown[]): string {
  let destString = srcString
  if (params) {
    const paramLen = params.length
    let expStr
    if (paramLen < 10) {
      expStr = `[1-${paramLen}]`
    } else {
      expStr = '[1-9]'
      for (let i = 10; i <= paramLen; i += 1) {
        expStr += `|${i}`
      }
    }
    const reg = new RegExp(`{(${expStr})}`, 'ig')
    destString = srcString.replace(reg, (match, index: number) => {
      return params[index - 1] as string
    })
  }

  return destString
}
